/** 
 * 2011-11-19 下午04:27:25  
 * @author zhaowg 
 * @version V1.0 
 */
package com.sample.springbatch.common;

/**
 * 自定的异常类
 * @author zhaowg 
 */
public class MyException extends  Exception{

	private static final long serialVersionUID = 71134982560437988L;

	private int errCode = 0;
	
	private String errMsg;
	
	public MyException(){
		super();
	}
	
	public MyException(int errCode){
		super("errCode:"+errCode);
		this.errCode = errCode;
	}
	
	public MyException(String errMsg){
		super(errMsg);
		this.errMsg = errMsg;
	}
	public MyException(ErrorCode errorCode){
		super(errorCode.getMsg());
		this.errCode = errorCode.getCode();
		this.errMsg = errorCode.getMsg();
	}

	public MyException(ErrorCode errorCode, String message){
		super(errorCode.getMsg());
		this.errCode = errorCode.getCode();
		if(message!=null && !message.isEmpty()){
			this.errMsg = message;
		}else{
			this.errMsg = errorCode.getMsg();
		}

	}
	
	public MyException(int errCode, String errMsg){
		super(errMsg);
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
	
	public MyException(Throwable cause){
		super(cause);
		if(cause!=null){
			this.errMsg = cause.getMessage();
		}
	}
	
	public MyException(int errCode, Throwable cause){
		super(cause);
		this.errCode = errCode;
		if(cause!=null){
			this.errMsg = cause.getMessage();
		}
	}

	public MyException(ErrorCode errorCode, Throwable cause){
		super(cause);
		this.errCode = errorCode.getCode();
		this.errMsg = errorCode.getMsg()+" "+cause.getMessage();
	}

	public int getErrCode() {
		return errCode;
	}

	public void setErrCode(int errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("{\"errCode\"=\"");
		builder.append(errCode);
		builder.append("\", \"errMsg\"=\"");
		builder.append(errMsg);
		builder.append("\"}");
		return builder.toString();
	}

	
}
